#!/bin/sh

project_dir=$(cd $(dirname $0)/../; pwd)
container_name="httplog"
image_name="randomos/staticpython:latest"

if [ "$1" = "--force" ]; then
    docker container inspect $container_name >/dev/null 2>&1
    if [ $? -eq 0 ]; then
        docker rm -f $container_name
    fi
fi

docker container inspect $container_name >/dev/null 2>&1
if [ $? -ne 0 ]; then
    docker create -it --hostname "$container_name" --name "$container_name" \
        -e TZ=Asia/Shanghai \
        -e SU_EXEC_USER=$(id -u):$(id -g) \
        -e CONF_DIR=/app/private \
        -v /dev/shm:/dev/shm \
        -v $project_dir:/app:ro \
        -v $project_dir/data/db:/app/data/db \
        -v $project_dir/logs:/app/logs \
        -p 8090:8080 \
        --restart=unless-stopped \
        $image_name /app/docker/run.sh
    docker start $container_name
fi
